package com.feib.stms.crypto;
/**
 * @(#)APDES.java
 *
 * APDES application
 *
 * @author 
 * @version 1.00 2008/7/25
 */
 
import java.io.*;
 
public class DESAP {
    
    public static void main(String[] args) {
       String sOut = "";
       String sData = "";
       	
       /* Key */
       if (args.length != 2 ) {
    	   System.out.println("[1].參數不足,APDES [MACKEY][File Name]!!");  	
       }else{
       	   try {
       	   	   String sKey = args[0];
	      	   File uploadedFile = new File(args[1]);
			   if(uploadedFile.exists()){
			   	   /* 讀取檔案 */
	      	       BufferedReader in = new BufferedReader(new FileReader(args[1]));
	      	       while ((sData = in.readLine()) != null) {
	      	           /* 依MAC值加密 */
	      	           sOut += DES.decryptData(sKey, sData) + "\r\n";
	      	       } 
	      	       in.close();	
	      	       /* 寫入檔案 */	
	      	       FileWriter out = new FileWriter(args[1] + ".txt"); 	
	      	       out.write(sOut);
	      	       out.close(); 	   
		           System.out.println("[0].解密成功，檔案輸出至" +args[1] + ".txt");
			   }else{
			   	   /* 開啟檔案失敗 */
			   	   System.out.println("[2].開啟檔案失敗!!");
			   }
   	       } catch (Exception e) {
		   	   System.out.println("[3].例外狀況發生, " + e.getMessage());
		   }	
       }	
    }
}
